#ifndef __MEMPOOL_H__
#define __MEMPOOL_H__

#include <pthread.h>

typedef void *(resource_pool_alloc_t)(void *pool_data);
typedef void (resource_pool_free_t)(void *element, void *pool_data);

typedef struct resource_pool_t {
	unsigned int min_nr;
	unsigned int curr_nr;
	void **elements;
	pthread_mutex_t lock;
	pthread_cond_t has_free_elements;
	resource_pool_alloc_t *alloc;
	resource_pool_free_t *free;
	void *pool_data;
} resource_pool_t;

resource_pool_t *resource_pool_create(int min_nr, resource_pool_alloc_t *alloc_fn, resource_pool_free_t *free_fn, void *pool_data);

void resource_pool_destroy(resource_pool_t *pool);

void *resource_pool_alloc(resource_pool_t *pool);

void resource_pool_free(resource_pool_t *pool, void *element);

#endif//end of __MEMPOOL_H__
